<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;


use HiCommon\Model\Areas;
use HiCommon\Repository\OrderCheckpointRepository;
use HiCommon\Repository\ShopCountRepository;
use HiCommon\Repository\ShopRepository;
use HiCommon\Repository\ViewFinanceOrderPayRepository;
use HiCommon\Repository\ViewFinanceOrderRefundRepository;

class ShopService extends BaseService
{

    /**
     * 获取已经开通的城市-以及所管辖的区
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_open_city_and_area()
    {
        $data = ShopRepository::get_open_city();
        $arr_ids = array_column($data, 'city');

        //根据cityids查询城市和区域
        $result = AreasService::api_city_area_by_cityids($arr_ids);
        return hello_success('成功', $result['data']);
    }

    /**
     * 获取分页数据-检测机构列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_checkpoint_list($arr_search)
    {
        $data = ShopRepository::api_checkpoint_list($arr_search)->toarray();

        foreach ($data['data'] as &$value) {
            $value['check_score'] = $value['shop_score']['average_score'];
        }
        $data = list_page_data_for_api($data);
        return hello_success('成功', $data);
    }

    /**
     * 检测机构-商家详情 [商家详情+时间段+年检费用]
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_checkpoint_detail($n_id)
    {
        if ($n_id <= 0) {
            return hello_error('数据id不能为空');
        }
        $data = ShopRepository::api_checkpoint_detail($n_id);
        $data = $data->toarray();
        $data['check_score'] = $data['shop_score']['average_score'];

        if(is_null($data['expenses'])){
            $data['expenses'] = '';
        }
        if (stripos($data['expenses'], '><tbody>')) {
            $data['expenses'] = str_replace('><tbody>', ' align="center" width="100%"><tbody>', $data['expenses']);
        }
        if (stripos($data['expenses'], 'src="/')) {
            $data['expenses'] = str_replace('src="/', 'src="https://xdminiapi.chxing.cn/', $data['expenses']);
            $data['expenses'] = str_replace('/>', ' align="center" width="100%"/>', $data['expenses']);
        }

        if (is_null($data)) {
            return hello_error('数据不存在');
        }
        return hello_success('成功',$data );
    }


    /**
     * 首页数据-商户端
     *
     * @param int $n_shop_id
     *
     * @return array
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_shop_index($n_shop_id = 0)
    {
        $n_shop_id = intval($n_shop_id);
        if ($n_shop_id <= 0) {
            return hello_error('店铺id不能空');
        }

        //查询商户信息
        $arr_field = ['id','cate'];
        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
        $n_shop_cate = intval($arr_shop['cate']);
        if(!in_array($n_shop_cate,[1,2])){
            return hello_error('店铺类型错误',[],'当前版本不包含道路救援商户');
        }

        $arr_data = [];
        $arr_search = [
          'start'=>date('Y-m-d',strtotime('yesterday')),
          'end'=>date('Y-m-d')
        ];

        $arr_search['shop_id'] = $n_shop_id;
        $result = ShopService::api_shop_finance_index($arr_search);
        if($result['state'] != 0) {
            return $result;
        }
        $oc_shop_profit_data = collect($result['data']);
        $arr_data['yesterday'] = $oc_shop_profit_data->where('date',$arr_search['start'])->first();
        $arr_data['today'] = $oc_shop_profit_data->where('date',$arr_search['end'])->first();

        if($n_shop_cate == 1){
            //年检预约单-接单角标
            $result = OrderCheckpointRepository::njyy_waiting_order_num_for_shop($n_shop_id);
            $arr_data['checkpoint_waiting_order_num'] = $result;

        }

        return  hello_success('成功',$arr_data);

    }

    /**
     * 收益明细-商户端
     *
     * @param int $n_shop_id
     * @param array $arr_search
     *
     * @return array
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_app_shop_profit_index($n_shop_id = 0, $arr_search = [])
    {
        $n_shop_id = intval($n_shop_id);
        if ($n_shop_id <= 0) {
            return hello_error('店铺id不能空');
        }

        //日期处理
        $s_start_date = str_trim($arr_search['date_start']);
        $s_end_date = str_trim($arr_search['date_end']);
        $s_date_type = str_trim($arr_search['date_type']);
        if($s_start_date == ''){
            $s_start_date = date('Y-m').'-01';
        }
        else{
            $n_time_half_year_ago = strtotime(date('Y-m',strtotime('-5 month')).'-01 00:00:01');
            $n_time_start = strtotime($s_start_date.' 00:00:00');
            if($n_time_start === false){
                return hello_error('日期格式错误');
            }
            if($n_time_start <= 0){
                return hello_error('日期错误');
            }
            if($n_time_start < $n_time_half_year_ago){
                return hello_error('只能查询近6个月的数据');
            }
        }
        if($s_end_date == ''){
            $s_end_date = date('Y-m-d');
        }

        $arr_search['start'] = $s_start_date;
        $arr_search['end'] = $s_end_date;
        $arr_search['date_type'] = $s_date_type;
        $arr_search['shop_id'] = $n_shop_id;
        $arr_option = ['sort'=>'desc'];
        $result = ShopService::api_shop_finance_index($arr_search,$arr_option);


//        //查询商户信息
//        $arr_field = ['id','cate'];
//        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
//        $n_shop_cate = intval($arr_shop['cate']);
//
//        //商户收益查询中转
//        $result = ShopService::transfer_shop_profit_index($n_shop_cate,$n_shop_id,$s_start_date,$s_end_date,$s_date_type);
        return $result;

    }

    /**
     * 店铺图表统计
     *
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_graphs_statistics($n_shop_id = 0, $arr_search = [])
    {

        /*处理前置数据*/
        $n_shop_id = intval($n_shop_id);
        if ($n_shop_id <= 0) {
            return hello_error('店铺id不能空');
        }

        //查询商户信息
        $arr_field = ['id','cate'];
        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
        $n_shop_cate = intval($arr_shop['cate']);
        if(!in_array($n_shop_cate,[1,2,3])){
            return hello_error('店铺类型错误');
        }

        /*查询数据*/
        $s_date_type = str_trim($arr_search['date_type']);
        $arr_date = nearly_date($s_date_type);//处理搜索日期和日期类型
        $date_start = $arr_date['start'];
        $date_end = $arr_date['end'];
        $date_type = $arr_date['date_type'];
        $result = ShopService::order_statistics_for_shop($n_shop_id,$date_start,$date_end ,$date_type);

        $arr_data['date'] = $result['date'];

        /*数据后续处理*/
        if($n_shop_cate == 1){

            $arr_data['num'] = $result['total_num'];
            $arr_data['pay_price'] = $result['pay_price'];
            $arr_data['refund_price'] = $result['refund_price'];
            $arr_data['profit'] = $result['profit'];

            $arr_data['zijia_num'] = $result['njyy_geren_num'];
            $arr_data['daijia_num'] = $result['njyy_qiye_num'];

            $arr_data['total'] = collect($result['total_num'])->sum();
            $arr_data['cate'] = 1;

        }
        elseif ($n_shop_cate == 2){
            $arr_data['num'] = $result['total_num'];
            $arr_data['pay_price'] = $result['pay_price'];
            $arr_data['refund_price'] = $result['refund_price'];
            $arr_data['profit'] = $result['profit'];

            $arr_data['service_num'] = $result['wxfw_num'];
//            $arr_data['service_pay_price'] = $result[''];
//            $arr_data['service_refund_price'] = $result[''];
//            $arr_data['service_profit'] = $result[''];

            $arr_data['mall_num'] = $result['ptshp_num'];
//            $arr_data['mall_pay_price'] = $result[''];
//            $arr_data['mall_refund_price'] = $result[''];
//            $arr_data['mall_profit'] = $result[''];

            $arr_data['service_total'] = collect($result['wxfw_num'])->sum();
            $arr_data['mall_total'] = collect($result['mall_num'])->sum();
            $arr_data['cate'] = 2;
        }
        elseif ($n_shop_cate == 3){

            $arr_data['cate'] = 3;
        }


        return  hello_success('成功',$arr_data);






        $n_shop_id = intval($n_shop_id);
        if ($n_shop_id <= 0) {
            return hello_error('店铺id不能空');
        }

        //查询商户信息
        $arr_field = ['id','cate'];
        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
        $n_shop_cate = intval($arr_shop['cate']);

        //处理搜索日期和日期类型
        $arr_search = nearly_date($arr_search['date_type']);

        //统计数据
        switch ($n_shop_cate) {
            case 1:
                $result = ShopCheckpointService::api_graphs_statistics($arr_search, $n_shop_id);
                break;
            case 2:
                $result = ShopRepairstoreService::api_graphs_statistics($arr_search, $n_shop_id);
                break;
            default:
                $result = hello_error('店铺类型错误');
        }

        return $result;
    }


//    /**
//     * 商户近期数据统计
//     *
//     * @param int    $n_shop_id
//     * @param string $s_date_type 近7天week  近半月half_month  近一月month 近半年half_year
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function api_nearly_graphs_statistics($n_shop_id = 0, $s_date_type = ''){
//        $n_shop_id = intval($n_shop_id);
//        if ($n_shop_id <= 0) {
//            return hello_error('店铺id不能空');
//        }
//
//        //处理搜索日期和日期类型
//        $arr_search = real_nearly_date($s_date_type);
//
//        //查询商户信息
//        $arr_field = ['id','cate'];
//        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
//        $n_shop_cate = intval($arr_shop['cate']);
//
//        //统计数据
//        switch ($n_shop_cate) {
//            case 1:
//                $result = ShopCheckpointService::api_graphs_statistics($arr_search, $n_shop_id);
//                break;
//            case 2:
//                $result = ShopRepairstoreService::api_graphs_statistics($arr_search, $n_shop_id);
//                break;
//            default:
//                $result = hello_error('店铺类型错误');
//        }
//
//        return $result;
//    }

//
//    /**
//     * 收益明细-商户后台
//     *
//     * @param int $n_shop_id
//     * @param array $arr_search
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function api_shop_profit_index($n_shop_id = 0, $arr_search = [])
//    {
//        $n_shop_id = intval($n_shop_id);
//        if ($n_shop_id <= 0) {
//            return hello_error('店铺id不能空');
//        }
//
//        //查询商户信息
//        $arr_field = ['id','cate'];
//        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
//        $n_shop_cate = intval($arr_shop['cate']);
//
//        //处理日期
//        $s_start_date = str_trim($arr_search['date_start']);
//        $s_end_date = str_trim($arr_search['date_end']);
//        $s_date_type = str_trim($arr_search['date_type']);
//        if($s_start_date == ''){
//            $s_start_date = date('Y-m').'-01';
//        }
//        if($s_end_date == ''){
//            $s_end_date = date('Y-m-d');
//        }
//
//        //商户收益查询中转
//        $result = ShopService::transfer_shop_profit_index($n_shop_cate,$n_shop_id,$s_start_date,$s_end_date,$s_date_type);
//        return $result;
//
//    }

//    /*商户收益查询中转-商户后台*/
//    public function transfer_shop_profit_index($n_shop_cate,$n_shop_id,$s_start_date,$s_end_date,$s_date_type){
//        switch ($n_shop_cate) {
//            case 1:
////                $result = ShopCheckpointService::api_profit_index( $n_shop_id,$s_start_date,$s_end_date,$s_date_type);
//                break;
//            case 2:
////                $result = ShopRepairstoreService::api_profit_index($n_shop_id,$s_start_date,$s_end_date,$s_date_type);
//                break;
//            default:
//                $result = hello_error('店铺类型错误');
//        }
//
//        $result['shop_cate'] = $n_shop_cate;
//
//        return $result;
//
//    }

    /**
     * 财务统计
     *
     * @param array $arr_search
     *
     * @return array
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_shop_finance_index($arr_search = [],$arr_option = []){
        $n_shop_id = intval($arr_search['shop_id']);

        $s_display = isset($arr_option['display']) ? $arr_option['display']:'all';
        $s_sort = isset($arr_option['sort']) ? $arr_option['sort']:'asc';
        $s_model = isset($arr_option['model']) ? $arr_option['model']:'shop';

        if($s_model === 'shop'){
            /*处理前置数据*/
            if ($n_shop_id <= 0) {
                return hello_error('店铺id不能空');
            }

            //查询商户信息
            $arr_field = ['id','cate'];
            $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
            $n_shop_cate = intval($arr_shop['cate']);
            if(!in_array($n_shop_cate,[1,2,3])){
                return hello_error('店铺类型错误');
            }
        }

        /*查询数据*/
        $nn_start = date('Y-m').'-01';
        $nn_end = date('Y-m-d');
        $date_start = empty($arr_search['start'])? $nn_start:str_trim($arr_search['start']);
        $date_end = empty($arr_search['end'])? $nn_end:str_trim($arr_search['end']);
        $date_type = str_trim($arr_search['date_type']);
        $result = ShopService::order_statistics_for_shop($n_shop_id,$date_start,$date_end ,$date_type);
        $arr_date_aa = $result['date'];
        $arr_total_num = $result['total_num'];
        $arr_pay_price = $result['pay_price'];
        $arr_refund_price = $result['refund_price'];
        $arr_profit = $result['profit'];

        //处理数据
        $arr_data = [];
        foreach ($arr_date_aa as $key=>$value)
        {
            $n_num = $arr_total_num[$key];
            $n_pay_price = $arr_pay_price[$key];
            $n_refund_price = $arr_refund_price[$key];
            $n_profit = $arr_profit[$key];

            if($s_display === 'all'){
                $arr_data[] = [
                  'date'=>$value,
                  'pay_price'=>$n_pay_price,
                  'refund_price'=>$n_refund_price,
                  'profit'=>$n_profit,
                  'num'=>$n_num
                ];
            }
            else{
                if(!($n_pay_price == 0 && $n_refund_price == 0 && $n_num == 0)){
                    $arr_data[] = [
                      'date'=>$value,
                      'pay_price'=>$n_pay_price,
                      'refund_price'=>$n_refund_price,
                      'profit'=>$n_profit,
                      'num'=>$n_num
                    ];
                }
            }


        }

        if($s_sort !== 'asc') {
            $arr_data = array_reverse($arr_data);
        }
        return  hello_success('成功',$arr_data);
    }


    /**
     * 商户近期订单数据统计-图表
     *
     * @param int    $n_shop_id
     * @param string $s_date_type 近7天week  近半月half_month  近一月month 近半年half_year
     *
     * @return array
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_nearly_order_graphs($n_shop_id = 0, $s_date_type = ''){

        /*处理前置数据*/
        $n_shop_id = intval($n_shop_id);
        if ($n_shop_id <= 0) {
            return hello_error('店铺id不能空');
        }

        //查询商户信息
        $arr_field = ['id','cate'];
        $arr_shop = get_shop_by_id($n_shop_id,$arr_field);
        $n_shop_cate = intval($arr_shop['cate']);
        if(!in_array($n_shop_cate,[1,2,3])){
            return hello_error('店铺类型错误');
        }

        /*查询数据*/
        $arr_date = real_nearly_date($s_date_type);//处理搜索日期和日期类型
        $date_start = $arr_date['start'];
        $date_end = $arr_date['end'];
        $date_type = $arr_date['date_type'];
        $result = ShopService::order_statistics_for_shop($n_shop_id,$date_start,$date_end ,$date_type);

        $arr_data['date'] = $result['date'];

        /*数据后续处理*/
        if($n_shop_cate == 1){
            $arr_data['chart_one'] = [
              'chart_name'=>'商户订单',
              'name'=>[
                'total'=>'总单数',
                'geren'=>'个人单',
                'qiye'=>'企业单',
              ],
              'total'=>$result['total_num'],
              'geren'=>$result['njyy_geren_num'],
              'qiye'=>$result['njyy_qiye_num'],
            ];
            $arr_data['cate'] = 1;
        }
        elseif ($n_shop_cate == 2){
            $arr_data['chart_one'] = [
              'chart_name'=>'商户订单',
              'name'=>[
                'total'=>'总单数',
                'ptshp'=>'普通商品',
                'wxfw'=>'维修服务',
                'wxby'=>'维修保养',
              ],
              'total'=>$result['total_num'],
              'ptshp'=>$result['ptshp_num'],
              'wxfw'=>$result['wxfw_num'],
              'wxby'=>$result['wxby_num'],
            ];
            $arr_data['cate'] = 2;
        }
        elseif ($n_shop_cate == 3){
            $arr_data['chart_one'] = [
              'chart_name'=>'商户订单',
              'name'=>[
                'total'=>'总单数',
              ],
              'total'=>$result['total_num'],
            ];
            $arr_data['cate'] = 3;
        }

        $arr_data['chart_two'] = [
          'chart_name'=>'商户收益',
          'name'=>[
            'pay_price'=>'总收入',
            'refund_price'=>'总退款',
            'profit'=>'总收益',
          ],
          'pay_price'=>$result['pay_price'],
          'refund_price'=>$result['refund_price'],
          'profit'=>$result['profit'],
        ];
        

        return  hello_success('成功',$arr_data);
//
//
//
//
//        //统计数据
//        switch ($n_shop_cate) {
//            case 1:
//                $result = ShopService::jiance_order_graphs($n_shop_id,$arr_search);
//                break;
//            case 2:
//                $result = ShopService::weixiu_order_graphs($n_shop_id,$arr_search);
//                break;
//            case 3:
////                $result = ShopService::weixiu_order_graphs($n_shop_id,$arr_search);
//                $result = [];
//                break;
//            default:
//                $result = hello_error('店铺类型错误');
//        }
//
//        return $result;
    }

    /*检测机构-图表数据*/
//    public function jiance_order_graphs($n_shop_id,$arr_search){
//        $arr_search['shop_id'] = $n_shop_id;
//        $arr_date_range = get_date_from_range($arr_search);
//        if(empty($arr_date_range)){
//            return hello_error('日期区间错误');
//        }
//        $arr_dates = $arr_date_range['dates'];//日期区间
//        sort($arr_dates);
//
//        //检测机构-指定日期接单总数
//        $count_num = ViewFinanceOrderPayRepository::jiance_order_count_num($arr_search);
//
//        //年检预约单-个人单-指定日期接单总数
//        $count_num_geren = ViewFinanceOrderPayRepository::jc_njyy_geren_order_count_num($arr_search);
//
//        //年检预约单-企业单-指定日期接单总数
//        $count_num_qiye = ViewFinanceOrderPayRepository::jc_njyy_qiye_order_count_num($arr_search);
//
//        //指定日期总交易额度
//        $sum_price = ViewFinanceOrderPayRepository::jc_njyy_order_sum_price($arr_search);
//
//        //指定日期退款额度
//        $sum_refund_price = ViewFinanceOrderRefundRepository::jc_njyy_order_sum_refund_price($arr_search);
//
//        $arr_data = [];
//        foreach ($arr_dates as $value)
//        {
//            $n_num = intval($count_num->where('date',$value)->first()->num);
//            $n_geren_num = intval($count_num_geren->where('date',$value)->first()->num);
//            $n_qiye_num = intval($count_num_qiye->where('date',$value)->first()->num);
//
//            $pay_price = $sum_price->where('date',$value)->first()->sum_pay_fee/100;
//            $n_pay_price = number_format_money($pay_price);
//
//            $refund_price = $sum_refund_price->where('date',$value)->first()->sum_refund_fee/100;
//            $n_refund_price = number_format_money($refund_price);
//
//            $n_profit = bcsub($n_pay_price,$n_refund_price,2);
//
//            //订单日期
//            $arr_data['date'][] = $value;
//
//            //订单数
//            $arr_data['chart_one']['total'][] = $n_num;
//            $arr_data['chart_one']['geren'][] = $n_geren_num;
//            $arr_data['chart_one']['qiye'][] = $n_qiye_num;
//
//            //订单收益
//            $arr_data['chart_two']['pay_price'][] = $n_pay_price;
//            $arr_data['chart_two']['refund_price'][] = $n_refund_price;
//            $arr_data['chart_two']['profit'][] = $n_profit;
//        }
//
//        $arr_data['chart_one']['chart_name'] = '商户订单';
//        $arr_data['chart_one']['name'] = [
//          'total'=>'总单数',
//          'geren'=>'个人单',
//          'qiye'=>'企业单',
//        ];
//
//        $arr_data['chart_two']['chart_name'] = '商户收益';
//        $arr_data['chart_two']['name'] = [
//          'pay_price'=>'总收入',
//          'refund_price'=>'总退款',
//          'profit'=>'总收益',
//        ];
//
//        //时间区间内总接单数
//        $n_total = intval($count_num->sum('num'));
//        $arr_data['total'] = $n_total;
//        $arr_data['cate'] = 1;
//
//        return  hello_success('查询成功',$arr_data);
//    }

    public function order_statistics_for_shop($n_shop_id = 0,$date_start = '',$date_end = '',$date_type = 'Ymd'){
        $arr_search['shop_id'] = $n_shop_id;
        $arr_search['start'] = $date_start;
        $arr_search['end'] = $date_end;
        $arr_search['date_type'] = $date_type;
        $arr_date_range = get_date_from_range($arr_search);
        $arr_dates = $arr_date_range['dates'];//日期区间
        sort($arr_dates);

        /*** 指定日期数据 ***/

        /*公共*/
        $count_num = ViewFinanceOrderPayRepository::order_count_num($arr_search);//支付单总数
        $sum_price = ViewFinanceOrderPayRepository::order_sum_price($arr_search);//总交易金额
        $sum_refund_price = ViewFinanceOrderRefundRepository::order_sum_refund_price($arr_search);//退款金额

        /*检测机构*/
        $count_num_njyy = ViewFinanceOrderPayRepository::jc_njyy_order_count_num($arr_search);//年检预约单-支付单总数
        $count_num_njyy_geren = ViewFinanceOrderPayRepository::jc_njyy_geren_order_count_num($arr_search);//年检预约单-支付单总数
        $count_num_njyy_qiye = ViewFinanceOrderPayRepository::jc_njyy_qiye_order_count_num($arr_search);//年检预约单-支付单总数

        /*维修店*/
        $count_num_ptshp = ViewFinanceOrderPayRepository::wx_ptshp_order_count_num($arr_search);//普通商品单-支付单总数
        $count_num_wxfw = ViewFinanceOrderPayRepository::wx_wxfw_order_count_num($arr_search);//维修服务单-支付单总数
        $count_num_wxby = ViewFinanceOrderPayRepository::wx_wxby_order_count_num($arr_search);//维修保养单-支付单总数

        /*道路救援*/
        $count_num_dljy = ViewFinanceOrderPayRepository::dl_dljy_order_count_num($arr_search);//道路救援单-支付单总数
        foreach ($arr_dates as $value)
        {
            $n_total_num = intval($count_num->where('date',$value)->first()->num);
            $n_pay_price = fee_to_money($sum_price->where('date',$value)->first()->sum_pay_fee);
            $n_refund_price = fee_to_money($sum_refund_price->where('date',$value)->first()->sum_refund_fee);
            $n_profit = bcsub($n_pay_price,$n_refund_price,2);

            $n_njyy_num = intval($count_num_njyy->where('date',$value)->first()->num);
            $n_njyy_geren_num = intval($count_num_njyy_geren->where('date',$value)->first()->num);
            $n_njyy_qiye_num = intval($count_num_njyy_qiye->where('date',$value)->first()->num);

            $n_ptshp_num = intval($count_num_ptshp->where('date',$value)->first()->num);
            $n_wxfw_num = intval($count_num_wxfw->where('date',$value)->first()->num);
            $n_wxby_num = intval($count_num_wxby->where('date',$value)->first()->num);

            $n_dljy_num = intval($count_num_dljy->where('date',$value)->first()->num);



            //订单日期
            $arr_data['date'][] = $value;
            $arr_data['total_num'][] = $n_total_num;
            $arr_data['pay_price'][] = $n_pay_price;
            $arr_data['refund_price'][] = $n_refund_price;
            $arr_data['profit'][] = $n_profit;

            $arr_data['njyy_num'][] = $n_njyy_num;
            $arr_data['njyy_geren_num'][] = $n_njyy_geren_num;
            $arr_data['njyy_qiye_num'][] = $n_njyy_qiye_num;

            $arr_data['ptshp_num'][] = $n_ptshp_num;
            $arr_data['wxfw_num'][] = $n_wxfw_num;
            $arr_data['wxby_num'][] = $n_wxby_num;

            $arr_data['dljy_num'][] = $n_dljy_num;
        }

        return $arr_data;
    }


    /*维修店-图表数据*/
//    public function weixiu_order_graphs($n_shop_id,$arr_search){
//
//        $arr_data['date'] = $arr_date_riqi;
//        $arr_data['chart_one'] = [
//          'chart_name'=>'商户订单',
//          'name'=>[
//            'total'=>'总单数',
//            'ptshp'=>'普通商品',
//            'wxfw'=>'维修服务',
//            'wxby'=>'维修保养',
//          ],
//          'total'=>$arr_wx_total,
//          'ptshp'=>$arr_wx_ptshp,
//          'wxfw'=>$arr_wx_wxfw,
//          'wxby'=>$arr_wx_wxby,
//        ];
//        $arr_data['chart_two'] = [
//          'chart_name'=>'商户收益',
//          'name'=>[
//            'pay_price'=>'总收入',
//            'refund_price'=>'总退款',
//            'profit'=>'总收益',
//          ],
//          'pay_price'=>$arr_wx_pay_price,
//          'refund_price'=>$arr_wx_refund_price,
//          'profit'=>$arr_wx_profit,
//        ];
//
//
//        $arr_data['cate'] = 2;
//
//        return  hello_success('查询成功',$arr_data);
//    }


}